home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
354
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
2KB
Path: solon.com!not-for-mail
From: seebs@solutions.solon.com (Peter Seebach)
Newsgroups: comp.lang.c.moderated,comp.lang.c,comp.std.c
Subject: Re: HELP IN WRITING MY FIRST PROGRAM ASSINGMENT
Date: 22 Feb 1996 06:41:58 -0600
Organization: Usenet Fact Police (Undercover)
Approved: seebs
Message-ID: <4ghoam$dp4@solutions.solon.com>
References: <3127FF7A.6442C3B8@eden.com> <4gfhkj$3p8@solutions.solon.com> <4ggbi9$83k@solutions.solon.com> <4ghnnc$dj9@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
In article <4ghnnc$dj9@solutions.solon.com>,
Keith Edward O'hara <k-ohara@ux7.cso.uiuc.edu> wrote:
>Previously in comp.lang.c.moderated,
>>int
>>cmp(void *a, void *b) {
>> if (a < b) return -1;
>> if (a > b) return 1;
>> else return 0;
>>}
>was used as the callback function for qsort() (in an evil piece of code).
>So I had to try it. The qsort in Borland's library, and the one I wrote
>when I was learning C, both call the callback compare function with one
>address OUTSIDE the original array. In my qsort, I put the partitioning
>element in temporary storage (which I need anyway to do the swaps) and
>pass the address of the temporary storage as one argument to cmp().
Agh!
>Two questions follow:
>Did Peter Seebach know all along that the pointers passed to cmp() would be
>not in the same array on some systems?
>[No. -mod]
To clarify: I believe it is incorrect for the library to do so; although
it's pretty tenuous, the "which is called with two arguments that point to
the objects being compared" seems to mean that to me. My rationale is that
the compiler *cannot* prove that the objects do not depend on being parts
of a larger array. For instance, consider an array of 200 objects; sort
the first 100, with a comparison routine that compares not only the objects,
but the objects 100 further in the "real" array. I believe this to be
conforming.
>Does the standard (which I don't have to own since I'm not posting to
>comp.std.c) disallow this behavior of qsort()?
>[I hope so.]
Crossposted to comp.std.c.
BTW, while we're at it, is it legal for nmemb to be 0 for qsort? I'd assume
it would just return.
-s
--
Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
FUCK the communications decency act. Goddamned government. [literally.]
The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.txt